added samples
[windows-sources.git] / sdk / samples / all in on code / Visual Studio 2008 / CSSL3SocketClient / App.xaml.cs
blobcfa39970522637a4eb61b95dd43e2aa0ed2a89f8
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Net;
5 using System.Windows;
6 using System.Windows.Controls;
7 using System.Windows.Documents;
8 using System.Windows.Input;
9 using System.Windows.Media;
10 using System.Windows.Media.Animation;
11 using System.Windows.Shapes;
13 namespace CSSL3SocketClient
15 public partial class App : Application
18 public App()
20 this.Startup += this.Application_Startup;
21 this.Exit += this.Application_Exit;
22 this.UnhandledException += this.Application_UnhandledException;
24 InitializeComponent();
27 private void Application_Startup(object sender, StartupEventArgs e)
29 this.RootVisual = new MainPage();
32 private void Application_Exit(object sender, EventArgs e)
36 private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
38 // If the app is running outside of the debugger then report the exception using
39 // the browser's exception mechanism. On IE this will display it a yellow alert
40 // icon in the status bar and Firefox will display a script error.
41 if (!System.Diagnostics.Debugger.IsAttached)
44 // NOTE: This will allow the application to continue running after an exception has been thrown
45 // but not handled.
46 // For production applications this error handling should be replaced with something that will
47 // report the error to the website and stop the application.
48 e.Handled = true;
49 Deployment.Current.Dispatcher.BeginInvoke(delegate { ReportErrorToDOM(e); });
52 private void ReportErrorToDOM(ApplicationUnhandledExceptionEventArgs e)
54 try
56 string errorMsg = e.ExceptionObject.Message + e.ExceptionObject.StackTrace;
57 errorMsg = errorMsg.Replace('"', '\'').Replace("\r\n", @"\n");
59 System.Windows.Browser.HtmlPage.Window.Eval("throw new Error(\"Unhandled Error in Silverlight Application " + errorMsg + "\");");
61 catch (Exception)